#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
typedef long long ll;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const int SIZE = 1<<19;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

template<int MOD>
struct ModInt {
  unsigned x;
  ModInt() : x(0) { }
  ModInt(signed sig) : x(sig) {  }
  ModInt(signed long long sig) : x(sig%MOD) { }
  int get() const { return (int)x; }
  ModInt pow(ll p) { ModInt res = 1, a = *this; while (p) { if (p & 1) res *= a; a *= a; p >>= 1; } return res; }
 
  ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
  ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
  ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
  ModInt &operator/=(ModInt that) { return (*this) *= that.pow(MOD - 2); }
 
  ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
  ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
  ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
  ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
  bool operator<(ModInt that) const { return x < that.x; }
  friend ostream& operator<<(ostream &os, ModInt a) { os << a.x; return os; }
};
typedef ModInt<1000000007> mint;

int n, tn;
string s, t;
string q;
int ls;
int qn;

mint p2[1000009];
mint ip2[1000009];
mint sp2[1000009][26];

mint ans = mint(0);

void solve(string,int);


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> tn;
    cin >> s >> t;
    ls = SZ(s);
    p2[0]=ip2[0]=mint(1);
    REPP(i,1,100009)p2[i]=p2[i-1]*2;
    ip2[1]=mint(1)/2;
    cout<<ip2[1].x<<endl;
    REPP(i,2,100009)ip2[i]=ip2[i-1]*ip2[1];
    REP(i,26)sp2[0][i]=mint(0);
    REP(i,SZ(t)){
        REP(j,26){
            if(t[i]-'a'==j){sp2[i+1][j]=sp2[i][j]+ip2[i];}
            else sp2[i+1][j]=sp2[i][j];
        }
    }
    REP(ti,tn){
        ans = mint(0);
        cin >> qn >> q;
        REP(i,ls+1){//start at which modulo of i
            string re;
            bool legit = 1;
            REP(j,SZ(q)){
                if(j%(ls+1)==i){//special
                    re += q[j];
                }
                else{
                    int nj = j%(ls+1);
                    if (nj>=i)nj--;
                    //printf("%d QUERY %d\n",j, nj);
                    if(q[j]!=s[(nj-i+ls)%ls]){
                        legit = 0;break;
                    }
                }
            }
            //cout << "p1 " << re << endl;
            if(!legit)continue;
            //cout << "p2 " << re << endl;
            solve(re, 0);
        }
        cout << ans << '\n';
    }
}

void solve(string q, int qi) {
    //printf("SOLVE %s %d\n",q.c_str(),qi);
    if(qi > qn)return;
    if (SZ(q)==0) {
        //printf("ADD %d\n",qn-qi);
        ans += p2[qn-qi];
        return;
    }
    if (SZ(q)==1){
        ans += mint(sp2[qn][q[0]-'a']-sp2[qi][q[0]-'a'])*p2[qn-1];
        return;
    }
    bool l = 1;
    for(int j=0;j<SZ(q);j+=2){
        if(q[j]!=t[qi]){l=0;break;}
    }
    if(l){
        string nq;
        for(int j=1;j<SZ(q);j+=2){
            nq+=q[j];
        }
        solve(nq, qi+1);
    }
    l = 1;
    for(int j=1;j<SZ(q);j+=2){
        if(q[j]!=t[qi]){l=0;break;}
    }
    if(l){
        string nq;
        for(int j=0;j<SZ(q);j+=2){
            nq+=q[j];
        }
        solve(nq, qi+1);
    }
}
